<?php

use yii\db\Migration;

class m170302_035414_alter_goods_group extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }


    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%goods_group}}', 'discount_type',  $this->smallInteger(2).' default 0 comment \'优惠类型（1，按比例 2 固定减额）\'');
            $this->addColumn('{{%goods_group}}', 'cost_reduce',  $this->decimal(10,2).' default 0 comment \'成本减少（比例较少整数）\'');
            $this->addColumn('{{%goods_group}}', 'market_price_reduce',  $this->decimal(10,2).' default 0 comment \'市场价减少（比例整数）\'');
            $this->addColumn('{{%goods_group}}', 'price_reduce',  $this->decimal(10,2).' default 0 comment \'销售价减少（比例整数）\'');
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%goods_group}}', 'discount_type');
            $this->dropColumn('{{%goods_group}}', 'cost_reduce');
            $this->dropColumn('{{%goods_group}}', 'market_price_reduce');
            $this->dropColumn('{{%goods_group}}', 'price_reduce');
        }
    }
}
